package com.xing.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xing.commonutils.R;
import com.xing.serviceedu.entity.EduCourse;
import com.xing.serviceedu.entity.EduTeacher;
import com.xing.serviceedu.service.EduCourseService;
import com.xing.serviceedu.service.EduTeacherService;
import org.apache.commons.collections4.Get;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/a/b")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    /**
     * 分页查询讲师
     *
     * @param page
     * @param limit
     * @return
     */
//    @PostMapping("getTeacherFrontList/{page}/{limit}")
    @PostMapping("c/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit) {
        Page<EduTeacher> pageTeacher = new Page<>(page, limit);
        Map<String, Object> map = eduTeacherService.getTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }

    //讲师查询的功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        //1.查询讲师信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);

        //2.查询讲师课程的基本信息
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", teacherId);
        //讲师可能是一个课程也可能是多个课程
        List<EduCourse> courseList = eduCourseService.list(queryWrapper);
        return R.ok().data("teacher", eduTeacher).data("courseList", courseList);
    }
}
